<link rel="stylesheet" type="text/css" href="Assets/webuploader/webuploader.css">

<!--引入JS-->
<script type="text/javascript" src="Assets/webuploader/webuploader.min.js"></script>

<div class="page">
    <div class="hd">
        <h1 class="page_title">  增加渠道 </h1>
    </div>
    <div class="bd">

        <div class="weui_cells_title">  </div>
        <form action="">
            <div class="weui_cells">
                <div class="weui_cell">
                    <div class="weui_cell_hd"><label class="weui_label"> 标题 </label></div>
                    <div class="weui_cell_bd weui_cell_primary">
                        <input class="weui_input" type="text"  name="title" placeholder="请输入标题">
                    </div>
                </div>
                <div class="weui_cell">
                    <div class="weui_cell_hd"><label class="weui_label"> 链接 </label></div>
                    <div class="weui_cell_bd weui_cell_primary">
                        <input class="weui_input" type="text"  name="url" placeholder="链接格式为 http://xxx,https://xxx,tel://xxx ">
                    </div>
                </div>


                <div class="weui_cell">
                    <div class="uploader-list" style="padding: 5px"></div>
                    <div class="weui_cell_bd weui_cell_primary">
                        <a class="weui_btn weui_btn_default" id="chooseImage">选择图片</a>
                    </div>
                </div>

                <div class="weui_cell weui_cell_select">
                    <div class="weui_cell_bd weui_cell_primary">
                        <select class="weui_select" name="position">
                            <option selected="" value="index_float">  首页大图 </option>
                            <option value="under_title"> 标题下图 </option>
                            <option value="footer_pic">  底部图 </option>
                        </select>
                    </div>
                </div>


    <!--            <div class="weui_cell">-->
    <!--                <div class="weui_cell_hd"><label class="weui_label"> 电话 </label></div>-->
    <!--                <div class="weui_cell_bd weui_cell_primary">-->
    <!--                    <input class="weui_input" type="text"  name="phone" placeholder="请输入电话">-->
    <!--                </div>-->
    <!--            </div>-->
    <!--            <div class="weui_btn_area">-->
    <!---->
    <!--                <div id="webuploader">-->
    <!--                    <!--用来存放item-->
    <!--                    <div id="fileList" class="uploader-list"></div>-->
    <!--                    <div id="filePicker">选择图片</div>-->
    <!--                </div>-->
    <!--            </div>-->

                <div class="weui_cell">
                    <input  type="hidden"  name="submit" value="1"  >
                    <input  type="hidden"  name="id"  value="<?php t_($this->input->get('id'));?>">
                    <input  type="hidden"  name="phone"  value="" >
                    <input  type="hidden"  name="pic"   id="pic_val" >
                </div>

                <div class="weui_btn_area">
                    <button type="submit" class="weui_btn weui_btn_primary" href="javascript:" id="showTooltips">确定</button>
                </div>
                <div class="weui_btn_area">
                    <a  onclick="history.go(-1);" class="weui_btn weui_btn_default" href="javascript:" id="showTooltips">返回</a>
                </div>
            </div>
        </form>

        <script>
            wx.ready(function () {
                document.querySelector('#chooseImage').onclick = function () {
                    wx.chooseImage({
                        count:1,
                        success: function (res) {
                            wx.uploadImage({
                                localId: res.localIds[0],
                                isShowProgressTips: 1, // 默觉得1，显示运行进度提示
                                success: function (res) {
                                    var serverId = res.serverId;
                                    $.ajax({
                                        url:"/upload_wexin",
                                        data:{serverId:serverId},
                                        success:function(res){
                                            var src = res.data;
                                            $("#pic_val").val(src);
                                            $(".uploader-list").html("<img src='"+src+"' style='width:80px;height:80px;'>");
                                        },
                                        error:function(res){alert(JSON.stringify(res))},
                                    });
                                },
                                fail: function (res) {
                                    alert(JSON.stringify(res))
                                }
                            });
                        }
                    });
                };

            });

        </script>
<!--        <script>-->
<!--            var $ = jQuery,-->
<!--                $list = $('#fileList'),-->
<!--                thumbnailWidth = 80,-->
<!--                thumbnailHeight = 80;-->
<!--            uploader = WebUploader.create({-->
<!--                // runtimeOrder:'flash',-->
<!--                // swf文件路径-->
<!--                swf: "/Assets/webuploader/Uploader.swf",-->
<!--                // 文件接收服务端。-->
<!--                server: '/upload',-->
<!--                // 选择文件的按钮。可选。-->
<!--                // 内部根据当前运行是创建，可能是input元素，也可能是flash.-->
<!--                pick: '#filePicker',-->
<!--                // 只允许选择图片文件。-->
<!--                accept: {-->
<!--                    title: 'Images',-->
<!--                    extensions: 'gif,jpg,jpeg,bmp,png',-->
<!--                    mimeTypes: 'image/*'-->
<!--                }-->
<!--            });-->
<!--            uploader.on( 'fileQueued', function( file ) {-->
<!--                this.upload();-->
<!--            });-->
<!--            uploader.on( 'uploadSuccess', function( file , response) {-->
<!--                if(response.code){-->
<!--                    if(response.code == 1000){-->
<!--                        var src = response.data;-->
<!--                        $("#pic_val").val(src);-->
<!--                        //显示图片-->
<!--                        var $li = $(-->
<!--                            '<div id="' + file.id + '" class="file-item thumbnail">' +-->
<!--                            '<img>' +-->
<!--                            '<div class="info"></div>' +-->
<!--                            // '<div class="info">' + file.name + '</div>' +-->
<!--                            '</div>'-->
<!--                            ),-->
<!--                            $img = $li.find('img');-->
<!--                        // $list为容器jQuery实例-->
<!--                        $list.html( $li );-->
<!--                        uploader.makeThumb( file, function( error, src ) {-->
<!--                            if ( error ) {-->
<!--                                $img.replaceWith('<span>不能预览</span>');-->
<!--                                return;-->
<!--                            }-->
<!--                            $img.attr( 'src', src );-->
<!--                        }, thumbnailWidth, thumbnailHeight );-->
<!--                        //显示图片-->
<!--                    }-->
<!--                }-->
<!--                uploader.removeFile( file );-->
<!--            });-->
<!--        </script>-->
    </div>
</div>

